﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using ASoft.Msg;

namespace ASoft.Data
{
    [DataContract]
    [MsgVMAttribute]
    public class RootData
    {
        [DataMember]
        public PLCData _PLCData;
        public PLCData PLCData
        {
            get
            {
                if (_PLCData == null)
                {
                    _PLCData = new PLCData();
                }
                return _PLCData;

            }
        }

        [DataMember]
        bool _启用模似气象站;
        public bool 启用模似气象站
        {
            get
            {
                return _启用模似气象站;
            }
            set
            {
                var changed = _启用模似气象站 != value;
                if (changed)
                {
                    SetObserversData(EObserverType.气象站实时信息);
                }
                _启用模似气象站 = value;
            }
        }

        [DataMember]
        public int 数据记录间隔分钟数 { get; set; }


        #region 气象站模似信息

        [DataMember]
        WeatherStationBroadcastMsg _气象站模似信息;

        public WeatherStationBroadcastMsg 气象站模似信息
        {
            get
            {
                if (_气象站模似信息 == null)
                {
                    _气象站模似信息 = new WeatherStationBroadcastMsg();
                }
                return _气象站模似信息;

            }
        }

        #endregion

        #region

        WeatherStationReturnMsgBase _气象站实时信息;

        public WeatherStationReturnMsgBase 气象站实时信息
        {
            get
            {
                if (启用模似气象站)
                {
                    return 气象站模似信息;
                }
                return _气象站实时信息;
            }
            set
            {
                var changed = !string.Equals(_气象站实时信息, value);
                if (changed)
                {
                    SetObserversData(EObserverType.气象站实时信息);
                }
                _气象站实时信息 = value;
            }
        }

        #endregion

        #region 气象站设置信息

        [DataMember]
        WeatherStationSetMsg _气象站设备信息;

        public WeatherStationSetMsg 气象站设备信息
        {
            get
            {
                if (_气象站设备信息 == null)
                {
                    _气象站设备信息 = new WeatherStationSetMsg();
                }
                return _气象站设备信息;

            }
        }

        #endregion



        #region 温室集合

        [DataMember]
        List<RoomData> _温室集合;

        public List<RoomData> 温室集合
        {
            get
            {
                if (_温室集合 == null)
                {
                    _温室集合 = new List<RoomData>();
                }
                return _温室集合;

            }
        }

        #endregion

        #region _温室设置信息集合

        [DataMember]
        List<RoomSetMsg> _温室设置信息集合;

        public List<RoomSetMsg> 温室设置信息集合
        {
            get
            {
                if (_温室设置信息集合 == null)
                {
                    _温室设置信息集合 = new List<RoomSetMsg>();
                }

                温室集合.Where(p => _温室设置信息集合.Count(p1 => p1.Id == p.Id) == 0)
                    .Select(p => p.Id)
                    .ToList()
                    .ForEach(p => _温室设置信息集合.Add(new RoomSetMsg() { Id = p }));

                _温室设置信息集合.RemoveAll(p => 温室集合.Count(p1 => p1.Id == p.Id) == 0);

                return _温室设置信息集合;
            }
        }

        #endregion

        List<IDataObserver> _Observers;

        List<IDataObserver> Observers
        {
            get
            {
                if (_Observers == null)
                {
                    _Observers = new List<IDataObserver>();
                }
                return _Observers;
            }
        }

        public void SetObserversData(EObserverType observerType)
        {
            Observers.ForEach(p => p.SetData(this, observerType));
        }

        public void AddtObserver(IDataObserver dataObserver)
        {
            Observers.Add(dataObserver);
        }

        public void RemoveObserver(IDataObserver dataObserver)
        {
            Observers.Remove(dataObserver);
        }

        #region User

        [DataMember]
        List<UserData> _Users;

        public List<UserData> Users
        {
            get
            {
                if (_Users == null)
                {
                    _Users = new List<UserData>();
                }
                return _Users;

            }
        }
        #endregion

        [DataMember]
        List<int> _IgnoreRoomIds;

        public List<int> IgnoreRoomIds
        {
            get
            {
                if (_IgnoreRoomIds == null)
                {
                    _IgnoreRoomIds = new List<int>();
                }
                return _IgnoreRoomIds;

            }
        }

        #region 偏移

        [DataMember]
        [MsgVM]
        public int 偏移光照 { get; set; }

        [DataMember]
        [MsgVM]
        public int 偏移雨雪 { get; set; }

        [DataMember]
        [MsgVM]
        public Decimal 偏移风速 { get; set; }

        [DataMember]
        [MsgVM]
        public int 偏移风向 { get; set; }

        [DataMember]
        [MsgVM]
        public Decimal 偏移室外温度 { get; set; }

        #endregion

        #region Net

        [DataMember]
        public string 数据上传地址 { get; set; }

        [DataMember]
        public bool 启用数据上传 { get; set; }


        [DataMember]
        public string 客户代码 { get; set; }

        #endregion

        #region Phone

        [DataMember]
        public bool MsgEnable { get; set; }


        [DataMember]
        public string PhonePortName { get; set; }


        [DataMember]
        public int PhoneSerialOvertime { get; set; }


        [DataMember]
        public bool Phone1Enable { get; set; }


        [DataMember]
        public string Phone1Number { get; set; }


        [DataMember]
        public bool Phone2Enable { get; set; }


        [DataMember]
        public string Phone2Number { get; set; }

        [DataMember]
        public bool Phone3Enable { get; set; }


        [DataMember]
        public string Phone3Number { get; set; }



        #endregion
    }
}
